using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : Entity
{

    [Header("Attack details")]
    public float[] attackMovement;
    public bool isBusy { get; private set; }
    [Header("Move info")]
    public float moveSpeed = 12f;

    [Header("Jump info")]
    public float jumpForce = 15f;    

    [Header("Dash info")]
    public float dashDuration = 0.2f;
    public float dashSpeed = 12f;
    public float dashDir { get; private set; }
    public float dashCooldown = .5f;
    public float dashUsageTime;

   

    #region states
    public PlayerStateMachine stateMachine { get; private set; }
    public PlayerIdleState idleState { get; private set; }
    public PlayerMoveState moveState { get; private set; }
    public PlayerJumpState jumpState { get; private set; }
    public PlayerAirState airState { get; private set; }
    public PlayerDashState dashState { get; private set; }
    public PlayerWallSlideState wallSlideState { get; private set; }
    public PlayerWallJumpState wallJumpState { get; private set; }
    public PlayerPrimAttackState PrimeAttack { get; private set; }

    


    #endregion
    protected override void Awake()
    {
        stateMachine = new PlayerStateMachine();
        idleState = new PlayerIdleState(this,stateMachine,"Idle");
        moveState = new PlayerMoveState(this,stateMachine,"Move");
        jumpState = new PlayerJumpState(this, stateMachine, "Jump");
        airState = new PlayerAirState(this, stateMachine, "Jump");
        dashState = new PlayerDashState(this, stateMachine, "Dash");
        wallSlideState = new PlayerWallSlideState(this, stateMachine, "WallSlide");
        wallJumpState = new PlayerWallJumpState(this, stateMachine, "Jump");
        PrimeAttack = new PlayerPrimAttackState(this, stateMachine, "Attack");
    }
    protected override void Start()
    {
        base.Start();    
        stateMachine.Initialize(idleState);
    }
    protected override void Update()
    {
        base.Update();
        stateMachine.currentState.Update();
        CheckForDashInput();
        dashUsageTime -= Time.deltaTime;
        
    }
    public IEnumerator BusyFor(float _seconds)
    {
        isBusy = true;
        yield return new WaitForSeconds(_seconds);
        isBusy = false;

    }
    public void AnimationTrigger() => stateMachine.currentState.AnimationFinishTrigger();
    public void CheckForDashInput()
    {
        if (isWallDetected())
            return;
        if (Input.GetKeyDown(KeyCode.LeftShift) && dashUsageTime < 0)
        {
            dashUsageTime = dashCooldown;
            dashDir = Input.GetAxis("Horizontal");
            if (dashDir == 0)
            {
                dashDir = facingDir;
            }
            stateMachine.ChangeState(dashState);
        }
    }
}
